package com.mach.platform.sprider.dev;

import com.mach.platform.sprider.Conf;
import com.mach.platform.util.SqlHelper;

/*
    取得变频器数据抓取器,一个对象针对一个采集模块
 */
public class TransducerStatusKunHanDev extends GerenalStatusDev {

    protected String devName;

    protected SqlHelper sqls;

    protected  TransducerFaultStatusDev faultStatusDev;

    public TransducerStatusKunHanDev(String ip, Integer port, Integer devID, String devName, TransducerFaultStatusDev faultStatusDev) {
        super(ip,port,devID, devName);

        this.sqls  = Conf.getSqlHelper();

        this.devName = devName;

        this.faultStatusDev = faultStatusDev;
    }



    /*
      取变频器状态, Null则为无数据,0则为异常,1为正常
   */
    public Integer getStatus() {
        Integer result = 3;
        //02,03,02,00,33,BC,51,01,02,01,01,60,48,
        //02,03,04,00,33,00,00,39,3C,
        try {
            byte[] repdata = this.getDataRtu(0x61,1);
            byte[] data = ByteUtil.subData(repdata,3,2);
            data = ByteUtil.reverse(data);
            Integer value = ByteUtil.getShort(data) * 1;
            if(value > 4000){
                result = 1;
            }
            if(this.faultStatusDev != null){
                if(this.faultStatusDev.isFault() == 1){
                    result = 2;
                }
            }

        } catch (Exception e) {
            System.out.println("excep devId:" + this.devName + " " + e.getMessage());
        }


        return result;
    }


    public static void main(String[] args){
        TransducerStatusKunHanDev td = new TransducerStatusKunHanDev("192.168.3.91",8003,2,"14#变频器（PA2、PO2工艺24H）",null);
        Integer status = td.getStatus();
        System.out.println("status="+status);
    }


}
